package com.gwtgeo.ui.client.mvp.searchresults;

import java.util.Map;

import com.gwtgeo.service.model.Location;
import com.gwtgeo.ui.client.mvp.HasValues;
import com.gwtgeo.ui.client.mvp.adapter.HasValuesListGridAdapter;
import com.gwtgeo.ui.client.mvp.windowsmanager.WindowedDisplay;
import com.gwtgeo.ui.client.mvp.windowsmanager.WindowedView;
import com.smartgwt.client.types.HeaderControls;
import com.smartgwt.client.widgets.events.HasClickHandlers;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridField;

public class SearchResultsView extends WindowedView<ListGrid> implements
		SearchResultsPresenter.Display {

	public SearchResultsView() {
		super();
	}

	@Override
	protected ListGrid buildWidget() {

		ListGrid widget = new ListGrid();
		
		ListGridField idField = new ListGridField(SearchResultRecordMapper.ID,
				"Id");
		ListGridField nameField = new ListGridField(
				SearchResultRecordMapper.NAME, "Name");
		ListGridField longitudeField = new ListGridField(
				SearchResultRecordMapper.LONGITUDE, "Longitude");
		ListGridField latitudeField = new ListGridField(
				SearchResultRecordMapper.LATITUDE, "Latitude");

		widget.setFields(idField, nameField, longitudeField, latitudeField);

		widget.setWidth100();
		// TODO PMA20100207 use relative Height.
		widget.setHeight(300);

		return widget;
	}

	@Override
	protected int getWindowHeight() {
		return 300;
	}

	@Override
	protected String getWindowTitle() {
		return "Results";
	}

	@Override
	protected int getWindowWidth() {
		return 600;
	}

	@Override
	public HasValues<Location> getResults() {
		return new HasValuesListGridAdapter<Location>(widget,
				new SearchResultRecordMapper());
	}
	
	@Override
	protected void addHeaderControls(Map<String, HasClickHandlers> headers) {
		window.setHeaderControls(HeaderControls.HEADER_LABEL, headers
				.get(WindowedDisplay.MINIMIZE_HEADER));
	}

}
